package com.vvlive.caibao.smartcity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.bean.EnterpriseContact;
import com.vvlive.caibao.smartcity.utils.ImageUtil;
import com.vvlive.caibao.smartcity.utils.ViewHolderUtil;

import java.util.List;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/6/26.
 */
public class CustomersContactsAdapter extends BaseAdapter {

    private Context context;
    private List<EnterpriseContact> contacts;

    public CustomersContactsAdapter(Context context, List<EnterpriseContact> contacts) {
        this.context = context;
        this.contacts = contacts;
    }

    @Override
    public int getCount() {
        return contacts.size();
    }

    @Override
    public Object getItem(int position) {
        return contacts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_customerscontacts_list, null);
        }
        ImageView avatar = ViewHolderUtil.get(convertView, R.id.cc_avatar);
        TextView name = ViewHolderUtil.get(convertView, R.id.cc_name);
        TextView type = ViewHolderUtil.get(convertView, R.id.cc_type);
        EnterpriseContact contact = contacts.get(position);
        avatar.setTag(contact.getPortrait());
        ImageUtil.loadImage(context, avatar, 0);
        name.setText(contact.getName());
        type.setText(contact.getType());
        return convertView;
    }
}
